package com.yjz.util.excel;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;

/**
 * @Author: tlfu
 * @Date: 2019-07-01 15:53
 */


public class DefaultExcelExportStyler implements IExcelExportStyler {

  protected Workbook workbook;

  public DefaultExcelExportStyler(Workbook workbook) {
    this.workbook = workbook;
  }

  @Override
  public CellStyle getHeaderStyle() {
    CellStyle style = workbook.createCellStyle(); // 标题样式
    style.setAlignment(CellStyle.ALIGN_CENTER); // 水平居中
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // 垂直居中
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setWrapText(true);
    style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
    style.setFillBackgroundColor(HSSFColor.GREY_40_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    return style;
  }

  @Override
  public CellStyle getTitleStyle() {
    CellStyle style = workbook.createCellStyle(); // 标题样式
    style.setAlignment(CellStyle.ALIGN_CENTER); // 水平居中
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // 垂直居中

    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 20);
    font.setFontName("IMPACT");
    font.setItalic(true);
    font.setColor(HSSFColor.BLUE_GREY.index);
    style.setFont(font);
    return style;
  }

  @Override
  public CellStyle getCellStyle() {
    CellStyle style = workbook.createCellStyle(); // 单元格样式
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // 垂直居中
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setBorderTop(CellStyle.BORDER_THIN);
    return style;
  }
}
